#/bin/bash

set -x
root_dir=$(cd $(dirname $0) && pwd)

_deb() {
	debname=$(echo $(basename $1) | sed 's/_.*//')
	echo $debname
	dpkg -V $debname
	if [ $? -ne 0 ]; then
		dpkg -i $1
	fi
}

_whl() {
	pip2 install -U --upgrade-strategy eager --no-index --timeout 1 --retries 0 --force-reinstall $@
}

_whl3() {
	python3 -m pip install -U --upgrade-strategy eager --no-index --timeout 1 --retries 0 --force-reinstall $@
}

_install_deb() {
	# _deb $root_dir/../depends/nginx/sgml-base_1.29_all.deb
	# _deb $root_dir/../depends/nginx/libxml2_2.9.4+dfsg1-2.2.deb
	# _deb $root_dir/../depends/nginx/fonts-dejavu-core_2.37-1_all.deb
	# _deb $root_dir/../depends/nginx/fontconfig-config_2.11.0-6.7_all.deb
	# _deb $root_dir/../depends/nginx/geoip-database_20170512-1_all.deb
	# _deb $root_dir/../depends/nginx/libfontconfig1.deb
	# _deb $root_dir/../depends/nginx/libjpeg62-turbo_1.deb
	# _deb $root_dir/../depends/nginx/libjbig0.deb
	# _deb $root_dir/../depends/nginx/libtiff5_4.0.8.deb
	# _deb $root_dir/../depends/nginx/libwebp6_0.5.2.deb
	# _deb $root_dir/../depends/nginx/libxpm4.deb
	# _deb $root_dir/../depends/nginx/libgd3.deb
	# _deb $root_dir/../depends/nginx/libgeoip1.deb
	# _deb $root_dir/../depends/nginx/nginx-common_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-auth-pam_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-dav-ext_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-echo_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-geoip_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-image-filter_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-subs-filter_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-upstream-fair_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libxslt1.1_1.1.29.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-http-xslt-filter_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-mail_1.10.3.deb
	# _deb $root_dir/../depends/nginx/libnginx-mod-stream_1.10.3.deb
	# _deb $root_dir/../depends/nginx/nginx-full_1.10.3.deb
	# _deb $root_dir/../depends/nginx/nginx_1.10.3.deb
	# _deb $root_dir/../depends/nginx/xml-core_0.17_all.deb
	# TODO: 需要补充
	# _deb $root_dir/../depends/lsof_4.89+dfsg-0.1.deb
	return
}

_install_whl() {
	# _whl virtualenv -f $root_dir/../depends/virtualenv
	# _whl uWSGI -f $root_dir/../depends/addon_flask
	# _whl Flask -f $root_dir/../depends/addon_flask
	# _whl Flask_Cors -f $root_dir/../depends/addon_flask
	# _whl psutil -f $root_dir/../depends
	# _whl redis -f $root_dir/../depends
	# _whl3 concurrent_log_handler -f $root_dir/../depends/concurrent-log-handler
	# _whl3 portalocker -f $root_dir/../depends/portalocker
	# _whl3 aiohttp -f $root_dir/../depends/aiohttp
	# _whl3 python-socketio -f $root_dir/../depends/python-socketio
	# _whl3 pyftpdlib -f $root_dir/../depends/pyftpdlib
	# _whl3 redis -f $root_dir/../depends/redis
	# _whl3 netifaces -f $root_dir/../depends/netifaces
	# _whl3 grpcio -f $root_dir/../depends/grpcio
	# _whl3 protobuf -f $root_dir/../depends/protobuf
	# _whl jakamodule -f $root_dir/../
	# _whl addon_manager -f $root_dir/../
	# _whl pylog -f $root_dir/../
	return
}
set +e
echo "I $(date +"%Y\%m\%d %H:%M:%S:%6N") [$$:$$] Upgrade JKZUC ..."
# _install_deb
# _install_whl
echo "I $(date +"%Y\%m\%d %H:%M:%S:%6N") [$$:$$] Upgrade done"
set -e
